package com.rabbitmq.workqueue;

import com.rabbitmq.client.Channel;
import com.rabbitmq.util.ConnectionUtils;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @author yinxing
 * @date 2022-08-29
 */
public class Producer {

    private static final String QUEUE_NAME = "hello";

    public static void main(String[] args) throws IOException {
        Channel channel = ConnectionUtils.getChannel();
        /**
         * 生成一个队列
         * 1/队列名字
         * 2、是否持久化
         * 3、是否消息共享
         * 4、是否自动删除
         */
        Map<String, Object> arguments = new HashMap<>();
        arguments.put("","");
        channel.queueDeclare(QUEUE_NAME,false,false,false,arguments);
        Scanner scanner =new Scanner(System.in);
        while (scanner.hasNext()){
            String message = scanner.next();
            System.out.println("发送消息:" + message);
            channel.basicPublish("",QUEUE_NAME,null,message.getBytes());
        }
    }
}
